﻿<!--#include file="inc/common.asp" -->
<%
'Blog文章内容编辑页面
'
'author: evan zhao
'

  if userObj.userId=""  then
    call assertConnected()
    call closeDb()  
    response.clear
    response.redirect("login.asp?blog_id=" & blogObj.blogId & "&cat_id=" & blogCatObj.catId & "&content_id=" & request("content_id"))
    response.end
  end if
  call openDB
  
  if not userRightObj.canPost then
    message("您没有权限发表文章")
  end if


  if blogCatObj.isRSS then
    message("本文内容从RSS源自动获取，无法编辑")
  end if


  dim blogItem
  set blogItem = new BlogItemClass
  
  dim content_id, title, detail,more, excerpt, is_secret,start_date,end_date,cat_id, show_content
  dim cat_id_orig
  content_id = request("content_id")
  if not isEmpty(content_id) and content_id<>"" then
    content_id = clng(content_id)
  end if  
  
  show_content = null
  
  cat_id = blogCatObj.catId

  if request("dosave")<>"true" then
    if content_id<>"" then
        if not blogItem.load(content_id) then
            message("文章不存在")
        end if
        
        if  not userRightObj.canEditItem(blogItem) then 
            message("您没有权限编辑本文")
        end if
        
        title = blogItem.title              
        detail = blogItem.detail            
        more  = blogItem.more          
        excerpt = blogItem.excerpt
        is_secret = blogItem.isSecret
        start_date = blogItem.startDate    
        end_date = blogItem.endDate  
        cat_id = blogItem.catId
        show_content = blogItem.showContent

        'sql = " select user_id, title,detail,more,excerpt,is_secret,start_date, end_date,cat_id,show_content from blog_content where content_id=" & content_id
        'rs.open sql, conn, 1, 1
        'if rs.eof then
        '    content_id=""
        'else
        '    if userObj.userId<>rs("user_id") and not userRightObj.canDelete then 
        '        message("您没有权限编辑本文")
        '    end if
        '    title = rs("title")
        '    detail = rs("detail")
        '    more  = rs("more")
        '    excerpt = rs("excerpt")
        '    is_secret = rs("is_secret")
        '    start_date = rs("start_date")
        '    end_date = rs("end_date")
        '    cat_id = rs("cat_id")
        '    show_content = rs("show_content")
        'end if
        'rs.close()
        
    else
        start_date = now()
        end_date = start_date
    end if
  else '保存文章
    title = filterHTML(request("title"))
    detail = request("detail")
    more = request("more")
    if (request("use_rte")<>"true") then
        detail = filterHTML2(detail,true)
        more = filterHTML2(more,true)
    else
        detail = filterHTML2(detail,false)
        more = filterHTML2(more,false)
    end if        
    excerpt = filterHTML2(request("excerpt"), true)
    is_secret = false
    if request("is_secret")="true" then
        is_secret = true
    end if
    show_content = request("show_content")
    if show_content="true" then
        show_content=1
    elseif show_content="false" then
        show_content=0
    else    
        show_content=null
    end if    
    start_date = request("start_date")
    if (not isDate(start_date)) then
        start_date= now()
    end if
    end_date = request("end_date")
    if (not isDate(end_date)) then
        end_date= now()
    end if
    cat_id = request("_cat_id")
    if trim(cat_id)="" then
        cat_id = null
    else
        cat_id = clng(cat_id)    
    end if    
    
    if trim(title)="" then
      message("标题不能为空")
    end if

    sql = " select blog_id, content_id,user_id, user_name, title,detail,more,excerpt,is_secret,start_date, end_date,insert_time,update_time,cat_id,show_content,face from blog_content where content_id=" 
    if isEmpty(content_id) or content_id="" then
        sql = sql & "-1 "
    else
        sql = sql & content_id
    end if        
    
    rs.open sql, conn, 1, 3
    

    if content_id="" then
        rs.addNew()
        rs("blog_id") = blogObj.blogId
        rs("user_id") = userObj.userId
    	rs("user_name") =  userObj.userName
        rs("insert_time") = now()
    else    
        cat_id_orig = rs("cat_id")
    end if
    rs("title") = title
    rs("detail") = detail
    if trim(more)<>"" then
        rs("more") = more
    else
        rs("more") = null
    end if    
    if trim(excerpt)<>"" then
        rs("excerpt") = excerpt
    else
        rs("excerpt") = null
    end if    
    rs("is_secret") = is_secret
    rs("start_date") = start_date
    rs("end_date") = end_date
    rs("cat_id") = cat_id
    'response.write show_content
    'response.end
    rs("show_content") = show_content
    rs("update_time") = now()
    if not isNull(userObj.faceUrl) and not isEmpty(userObj.faceUrl) and userObj.faceUrl<>"" then
        rs("face") = userObj.faceUrl
    end if
    rs.update()
    
    content_id = rs("content_id")
    rs.close()
    
    'if content_id="" then
    '    sql = " insert into blog_content(blog_id, title, detail, excerpt, user_id, user_name, is_secret, start_date, end_date, cat_id, show_content) values " &_
    '          " (" & blogObj.blogId & ", '" & title &"', '" & detail &"', '" & excerpt &"'," & userObj.userId & ", '" & userObj.userName &"', " & is_secret & ", '" & start_date &"', '" & end_date &"', " &cat_id &", " &show_content &")"
    'else
    '    sql = " update blog_content set update_time=now(), title='" & title &"', detail='" & detail & "', excerpt='" & excerpt & "', is_secret=" & is_secret & " , start_date='" & start_date & "',  end_date='" & end_date & "', cat_id=" & cat_id & " , show_content=" & show_content & " where content_id=" & content_id
    'end if          
    'response.write(sql)    
    'response.end    
    'conn.execute(sql)
    
    call blogItem.reload(content_id)  

    call blogObj.loadTopItemsFromDB()
    call blogObj.cache()
    
    dim blogCatOrig, blogCatNew 
    if cat_id_orig<>cat_id then
        set blogCatOrig = new BlogCatClass
        call blogCatOrig.load(blogObj.blogId, cat_id_orig)
        call blogCatOrig.loadTotalItemCountFromDB()
        call blogCatOrig.cache()
    end if
    set blogCatNew = new BlogCatClass
    call blogCatNew.load(blogObj.blogId, cat_id)
    call blogCatNew.loadTotalItemCountFromDB()
    call blogCatNew.cache()

    call blogCatObj.loadTotalItemCountFromDB()
    call blogCatObj.cache()
    
    'message("保存成功！：）")
    call closeDB()
    response.redirect "index.asp?blog_id=" & blogObj.blogId & "&cat_id=" & blogCatObj.catId & "&pageno=" & request("pageno")
  
  end if

%>


<head>
<meta http-equiv="Content-Type" content="text/html; charset=<%=DEFAULT_CHARSET%>">
<title><%=blogObj.blogTitle%>—编辑</title>
<link rel="stylesheet" href="styles.css" type="text/css" />
<style  type="text/css">
td,input,select {font-size:x-small};
</style>

<script language="javascript">

function isIE(){
	if(document.all){
		return true;
	}
	return false;
}



function RTELoaded(editor){
    if (editor==itemBodyEditor){
        if (form1.detail.value!=""){
            editor.setHTML(form1.detail.value);
        }    

    }else if (editor==itemMoreEditor){
        if (form1.more.value!=""){
            editor.setHTML(form1.more.value);
        } 
		   
    }
}


function save(){
    theform = document.getElementById("form1")
    if (theform.title.value==""){
        alert("请输入标题");
        theform.title.focus();
        return false;
    }
    if(isIE()){
        if(itemBodyEditor.getText()!="" || itemBodyEditor.getHTML().indexOf("<IMG")>-1){
            theform.detail.value=itemBodyEditor.getHTML();
        }else{
            theform.detail.value="";
        }
 
        if(itemMoreEditor.getText()!="" || itemMoreEditor.getHTML().indexOf("<IMG")>-1){
            theform.more.value=itemMoreEditor.getHTML();
        }else{
            theform.more.value="";
        }
    }
    if (theform.detail.value==""){
        alert("请输入内容");
        return false;
    }
    
    theform.saveBtn.disabled=true;
    theform.dosave.value="true";
    return true;
}

</script>

</head>
<BODY >
<center>
<DIV id=container style=" background-color:transparent" align=center>
    <DIV id=banner>
        <h1><a href="index.asp?blog_id=<%=blogObj.blogId%>"><%=blogObj.blogTitle%></a>
<%
    if blogCatObj.catName<>"" then
%>
    -<a href="index.asp?blog_id=<%=blogCatObj.blogId%>&cat_id=<%=blogCatObj.catId%>"><%=blogCatObj.catName%></a>
<%
    end if
%></h1>
        <h2><%=filterHTML(blogObj.blogDesc)%></h2>
    </DIV>
        <br>
        <div class=content style="  background-color:#ffffff; width:100%">  
<div>
<form name=form1 id=form1 action=edit.asp method=post onsubmit="return save()">
<input type=hidden name=blog_id value="<%=blogObj.blogId%>">
<input type=hidden name=cat_id value="<%=blogCatObj.catId%>">
<input type=hidden name=pageno value="<%=request("pageno")%>">
<input type=hidden name=content_id value="<%=content_id%>">
<input type=hidden name=dosave >
<p><b>标题：</b><input type=text size=56 maxlength=99 name="title" value="<%=title%>">
&nbsp;<b>分类：</b><select name="_cat_id">
         <option value="">未分类</option>
<%
      sql = " select cat_id,  cat_name from blog_category  where blog_id=" & blogObj.blogId & " and is_rss = false order by display_seq"
      rs.open sql, conn, 1, 1
      if not rs.eof then
        do until rs.eof
%>          
        <option value="<%=rs("cat_id")%>" <% if cat_id=rs("cat_id") then response.write(" selected ") end if%> ><%=rs("cat_name")%></option>
<%
            rs.moveNext()
        loop
      end  if
      rs.close()
%>
          </select>
</p>
<p><b>内容摘要：</b><br>
	<textarea name="excerpt" rows=3 cols=73><%=excerpt%></textarea></p>
<p><b>文章主体:</b><br>
	<script language="javascript">
	    document.write('<textarea name=detail rows=20 cols=83');
	    if (isIE()){
	        document.write (' style="display:none" ');
	    }
	    document.write('>');
	</script><% if not isNull(detail) then 
	            'response.write replace(replace(replace(detail,"&","&amp;"),"<","&lt;"),">","&gt;") 
	            response.write Server.HTMLEncode(detail)
	        end if%></textarea>
	<script language="javascript">
	    if (isIE()){
		    document.write('<IFRAME id="itemBodyEditor" Name="itemBodyEditor" WIDTH="600px"  HEIGHT="360px"  SRC="rte/rte.htm"></IFRAME>'); 
	    	document.write('<input type=hidden name="use_rte" value="true">');
	    }
	</script>
</p>
<p><b>更多内容:</b><br>
	<script language="javascript">
	    document.write('<textarea name=more rows=20 cols=83');
	    if (isIE()){
	        document.write (' style="display:none" ');
	    }
	    document.write('>');
	</script><% if not isNull(more) then 
	            'response.write replace(replace(replace(more,"&","&amp;"),"<","&lt;"),">","&gt;") 
	            response.write Server.HTMLEncode(more)
	         end if%></textarea>
	<script language="javascript">
	    if (isIE()){
		    document.write('<IFRAME id="itemMoreEditor" Name="itemMoreEditor" style="WIDTH: 600px; HEIGHT: 360px"  SRC="rte/rte.htm"></IFRAME>'); 
	    }
	</script>
</p>
<p>
          开始日期：<input type=text name=start_date size=10 value="<%=FORMATDATETIME(start_date,vbShortDate)%>">&nbsp;
          结束日期：<input type=text name=end_date size=10 value="<%=FORMATDATETIME(end_date,vbShortDate)%>">&nbsp;
</p>
<p>
          内容是否默认显示：
          <select name=show_content>
            <option value="">缺省</option>
            <option value="true" <% if show_content=1 then response.write("selected") end if%> >显示</option>
            <option value="false" <% if show_content=0 then response.write(" selected") end if%> >隐藏</option>
          </select>  
          &nbsp;
          内容是否需要保密：
          <select name=is_secret >
            <option value="false">公开</option>
            <option value="true" <% if is_secret then response.write("selected") end if%> >保密</option>
          </select>  
</p>
<p >
          <input type=submit name=saveBtn  value="        确认提交        " size=10>
          <input type=button onclick="history.back()" value="  后退  " >
          <input type=button onclick="document.location.href='index.asp?blog_id=<%=blogObj.blogId%>&cat_id=<%=blogCatObj.catId%>&pageno=<%=request("pageno")%>'" value="  返回  " size=10>
</p> 
</form>
</div>
<p>&nbsp;</p>
        </div><!--end of content-->
        
</DIV>    
</center>   
</body>    
</html>    


<!--#include file="inc/end.asp" -->
